package jp.co.hcs.attendancemanagement.data.dao.impl;

import java.sql.SQLException;
import java.util.List;

import jp.co.hcs.attendancemanagement.data.dao.EffortActualDAO;
import jp.co.hcs.attendancemanagement.data.entity.EffortActual;
import jp.co.hcs.attendancemanagement.data.entity.ex.EffortActualExample;
import jp.co.hcs.attendancemanagement.data.entity.ex.EffortActualParameter;
import jp.co.hcs.attendancemanagement.inputdailyattendance.logic.dto.ProjectInfoDTO;
import jp.co.hcs.attendancemanagement.inputtableb.logic.dto.ProjectEffortInfoDTO;

public class EffortActualDAOImpl extends BaseDAOImpl implements EffortActualDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public EffortActualDAOImpl() {
        super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int countEffortActualByExample(EffortActualExample example) throws SQLException {
        Integer count = (Integer)  sqlMapClient.queryForObject("tb5_nkousu_jisseki.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int deleteEffortActualByExample(EffortActualExample example) throws SQLException {
        int rows = sqlMapClient.delete("tb5_nkousu_jisseki.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int deleteEffortActualByPrimaryKey(Short seqNo, String employeeId, String actualEffortDay, String actualEffortYearMonth) throws SQLException {
        EffortActual key = new EffortActual();
        key.setSeqNo(seqNo);
        key.setEmployeeId(employeeId);
        key.setActualEffortDay(actualEffortDay);
        key.setActualEffortYearMonth(actualEffortYearMonth);
        int rows = sqlMapClient.delete("tb5_nkousu_jisseki.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }
    
    public int deleteEffortActualInMonth(String employeeId, String workingId, String actualEffortYearMonth, String projectCode) throws SQLException {
    	EffortActual effortActual = new EffortActual();
    	effortActual.setProjectCode(projectCode);
    	effortActual.setEmployeeId(employeeId);
    	effortActual.setWorkingId(workingId);
    	effortActual.setActualEffortYearMonth(actualEffortYearMonth);
        int rows = sqlMapClient.delete("tb5_nkousu_jisseki.ibatorgenerated_deleteForMonth", effortActual);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public void insertEffortActual(EffortActual record) throws SQLException {
        sqlMapClient.insert("tb5_nkousu_jisseki.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public void insertEffortActualSelective(EffortActual record) throws SQLException {
        sqlMapClient.insert("tb5_nkousu_jisseki.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    @SuppressWarnings("unchecked")
    public List<EffortActual> selectEffortActualByExample(EffortActualExample example) throws SQLException {
        List<EffortActual> list = sqlMapClient.queryForList("tb5_nkousu_jisseki.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public EffortActual selectEffortActualByPrimaryKey(Short seqNo, String employeeId, String actualEffortDay, String actualEffortYearMonth) throws SQLException {
        EffortActual key = new EffortActual();
        key.setSeqNo(seqNo);
        key.setEmployeeId(employeeId);
        key.setActualEffortDay(actualEffortDay);
        key.setActualEffortYearMonth(actualEffortYearMonth);
        EffortActual record = (EffortActual) sqlMapClient.queryForObject("tb5_nkousu_jisseki.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int updateEffortActualByExampleSelective(EffortActual record, EffortActualExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_nkousu_jisseki.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int updateEffortActualByExample(EffortActual record, EffortActualExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_nkousu_jisseki.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int updateEffortActualByPrimaryKeySelective(EffortActual record) throws SQLException {
        int rows = sqlMapClient.update("tb5_nkousu_jisseki.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    public int updateEffortActualByPrimaryKey(EffortActual record) throws SQLException {
        int rows = sqlMapClient.update("tb5_nkousu_jisseki.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table tb5_nkousu_jisseki
     *
     * @ibatorgenerated Wed Mar 07 23:25:45 GMT+07:00 2012
     */
    private static class UpdateByExampleParms extends EffortActualExample {
        private Object record;

        public UpdateByExampleParms(Object record, EffortActualExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }
    
    public List<ProjectEffortInfoDTO> getListProjectEffortInfoDTO(EffortActualParameter effortActualParameter) throws SQLException
    {
    	@SuppressWarnings("unchecked")
		List<ProjectEffortInfoDTO> projectEffortInfoDTOList = (List<ProjectEffortInfoDTO>)sqlMapClient.queryForList("tb5_nkousu_jisseki.getprojectEffortInfoDTOList", effortActualParameter);
    	return projectEffortInfoDTOList;
    }
    
    public List<ProjectEffortInfoDTO> getListProjectEffortInfoDTOWithActualEffortDate(EffortActualParameter effortActualParameter) throws SQLException
    {
    	@SuppressWarnings("unchecked")
		List<ProjectEffortInfoDTO> projectEffortInfoDTOList = (List<ProjectEffortInfoDTO>)sqlMapClient.queryForList("tb5_nkousu_jisseki.getprojectEffortInfoDTOListWithActualEffortDate", effortActualParameter);
    	return projectEffortInfoDTOList;
    }
    
    @SuppressWarnings("unchecked")
	public List<ProjectInfoDTO> getProjectInfoDTOList(EffortActualParameter effortActualParameter) throws SQLException{
    	List<ProjectInfoDTO> projectInfoDTOList = sqlMapClient.queryForList("tb5_nkousu_jisseki.getProjectInfoDTOList", effortActualParameter);
    	return projectInfoDTOList;
    }
    
	public int deleteEffortActualInDay(String employeeId, String actualEffortDay, String actualEffortYearMonth) throws SQLException {
		EffortActual key = new EffortActual();
        key.setEmployeeId(employeeId);
        key.setActualEffortDay(actualEffortDay);
        key.setActualEffortYearMonth(actualEffortYearMonth);
        int rows = sqlMapClient.delete("tb5_nkousu_jisseki.deleteEffortActualInDay", key);
        return rows;
	}
    
    public int getMaxSEQNumber(EffortActualParameter effortActualParameter) throws SQLException{
    	int maxSEQ = 0;
    	Object result = sqlMapClient.queryForObject("tb5_nkousu_jisseki.getMaxSEQNumber", effortActualParameter);
    	if(result != null){
    		maxSEQ = Integer.parseInt(result.toString());
    	}
    	return maxSEQ;
    }

}